
PINCONF_FUNC_SHIFT =            (17)
PINCONF_FUNC_MASK =             (7 << PINCONF_FUNC_SHIFT)


PINCONF_FUNC0 =               (0 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC1 =               (1 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC2 =               (2 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC3 =               (3 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC4 =               (4 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC5 =               (5 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC6 =               (6 << PINCONF_FUNC_SHIFT)
PINCONF_FUNC7 =               (7 << PINCONF_FUNC_SHIFT)

PINCONF_INBUFFER =              (1 << 12)

PINCONF_PINS_SHIFT =            (5)
PINCONF_PINS_MASK =             (31 << PINCONF_PINS_SHIFT)
PINCONF_PINS0 =               (0 << PINCONF_PINS_SHIFT)
PINCONF_PINS1 =               (1 << PINCONF_PINS_SHIFT)
PINCONF_PINS2 =               (2 << PINCONF_PINS_SHIFT)
PINCONF_PINS3 =               (3 << PINCONF_PINS_SHIFT)
PINCONF_PINS4 =               (4 << PINCONF_PINS_SHIFT)
PINCONF_PINS5 =               (5 << PINCONF_PINS_SHIFT)
PINCONF_PINS6 =               (6 << PINCONF_PINS_SHIFT)
PINCONF_PINS7 =               (7 << PINCONF_PINS_SHIFT)
PINCONF_PINS8 =               (8 << PINCONF_PINS_SHIFT)
PINCONF_PINS9 =               (9 << PINCONF_PINS_SHIFT)
PINCONF_PINSA =               (10 << PINCONF_PINS_SHIFT)
PINCONF_PINSB =               (11 << PINCONF_PINS_SHIFT)
PINCONF_PINSC =               (12 << PINCONF_PINS_SHIFT)
PINCONF_PINSD =               (13 << PINCONF_PINS_SHIFT)
PINCONF_PINSE =               (14 << PINCONF_PINS_SHIFT)
PINCONF_PINSF =               (15 << PINCONF_PINS_SHIFT)
PINCONF_PINSG =               (16 << PINCONF_PINS_SHIFT)
PINCONF_PINSH =               (17 << PINCONF_PINS_SHIFT)
PINCONF_PINSI =               (18 << PINCONF_PINS_SHIFT)
PINCONF_PINSJ =               (19 << PINCONF_PINS_SHIFT)
PINCONF_PINSK =               (20 << PINCONF_PINS_SHIFT)
PINCONF_PINSL =               (21 << PINCONF_PINS_SHIFT)
PINCONF_PINSM =               (22 << PINCONF_PINS_SHIFT)
PINCONF_PINSN =               (23 << PINCONF_PINS_SHIFT)
PINCONF_PINSO =               (24 << PINCONF_PINS_SHIFT)
PINCONF_PINSP =               (25 << PINCONF_PINS_SHIFT)
PINCONF_PINSQ =               (26 << PINCONF_PINS_SHIFT)
PINCONF_PINSR =               (27 << PINCONF_PINS_SHIFT)
PINCONF_PINSS =               (28 << PINCONF_PINS_SHIFT)
PINCONF_PINST =               (29 << PINCONF_PINS_SHIFT)
PINCONF_PINSU =               (30 << PINCONF_PINS_SHIFT)
PINCONF_PINSV =               (31 << PINCONF_PINS_SHIFT)


PINCONF_PIN_SHIFT =             (0)
PINCONF_PIN_MASK =              (31 << PINCONF_PIN_SHIFT)
PINCONF_PIN_0 =               (0 << PINCONF_PIN_SHIFT)
PINCONF_PIN_1 =               (1 << PINCONF_PIN_SHIFT)
PINCONF_PIN_2 =               (2 << PINCONF_PIN_SHIFT)
PINCONF_PIN_3 =               (3 << PINCONF_PIN_SHIFT)
PINCONF_PIN_4 =               (4 << PINCONF_PIN_SHIFT)
PINCONF_PIN_5 =               (5 << PINCONF_PIN_SHIFT)
PINCONF_PIN_6 =               (6 << PINCONF_PIN_SHIFT)
PINCONF_PIN_7 =               (7 << PINCONF_PIN_SHIFT)
PINCONF_PIN_8 =               (8 << PINCONF_PIN_SHIFT)
PINCONF_PIN_9 =               (9 << PINCONF_PIN_SHIFT)
PINCONF_PIN_10 =              (10 << PINCONF_PIN_SHIFT)
PINCONF_PIN_11 =              (11 << PINCONF_PIN_SHIFT)
PINCONF_PIN_12 =              (12 << PINCONF_PIN_SHIFT)
PINCONF_PIN_13 =              (13 << PINCONF_PIN_SHIFT)
PINCONF_PIN_14 =              (14 << PINCONF_PIN_SHIFT)
PINCONF_PIN_15 =              (15 << PINCONF_PIN_SHIFT)
PINCONF_PIN_16 =              (16 << PINCONF_PIN_SHIFT)
PINCONF_PIN_17 =              (17 << PINCONF_PIN_SHIFT)
PINCONF_PIN_18 =              (18 << PINCONF_PIN_SHIFT)
PINCONF_PIN_19 =              (19 << PINCONF_PIN_SHIFT)
PINCONF_PIN_20 =              (20 << PINCONF_PIN_SHIFT)
PINCONF_PIN_21 =              (21 << PINCONF_PIN_SHIFT)
PINCONF_PIN_22 =              (22 << PINCONF_PIN_SHIFT)
PINCONF_PIN_23 =              (23 << PINCONF_PIN_SHIFT)
PINCONF_PIN_24 =              (24 << PINCONF_PIN_SHIFT)
PINCONF_PIN_25 =              (25 << PINCONF_PIN_SHIFT)
PINCONF_PIN_26 =              (26 << PINCONF_PIN_SHIFT)
PINCONF_PIN_27 =              (27 << PINCONF_PIN_SHIFT)
PINCONF_PIN_28 =              (28 << PINCONF_PIN_SHIFT)
PINCONF_PIN_29 =              (29 << PINCONF_PIN_SHIFT)
PINCONF_PIN_30 =              (30 << PINCONF_PIN_SHIFT)
PINCONF_PIN_31 =              (31 << PINCONF_PIN_SHIFT)

PINCONF_GPIO0p0 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS0|PINCONF_PIN_0)
PINCONF_GPIO0p1 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS0|PINCONF_PIN_1)
PINCONF_GPIO0p2 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_15)
PINCONF_GPIO0p3 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_16)
PINCONF_GPIO0p4 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_0)
PINCONF_GPIO0p5 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_6)
PINCONF_GPIO0p6 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_6)
PINCONF_GPIO0p7 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_7)
PINCONF_GPIO0p8 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_1)
PINCONF_GPIO0p9 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_2)
PINCONF_GPIO0p10 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_3)
PINCONF_GPIO0p11 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_4)
PINCONF_GPIO0p12 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_17)
PINCONF_GPIO0p13 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_18)
PINCONF_GPIO0p14 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_10)
PINCONF_GPIO0p15 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_20)
PINCONF_GPIO1p0 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_7)
PINCONF_GPIO1p1 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_8)
PINCONF_GPIO1p2 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_9)
PINCONF_GPIO1p3 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_10)
PINCONF_GPIO1p4 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_11)
PINCONF_GPIO1p5 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_12)
PINCONF_GPIO1p6 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_13)
PINCONF_GPIO1p7 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_14)
PINCONF_GPIO1p8 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_5)
PINCONF_GPIO1p9 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS1|PINCONF_PIN_6)
PINCONF_GPIO1p10 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_9)
PINCONF_GPIO1p11 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_11)
PINCONF_GPIO1p12 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_12)
PINCONF_GPIO1p13 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_13)
PINCONF_GPIO1p14 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_4)
PINCONF_GPIO1p15 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_5)
PINCONF_GPIO2p0 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_0)
PINCONF_GPIO2p1 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_1)
PINCONF_GPIO2p2 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_2)
PINCONF_GPIO2p3 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_3)
PINCONF_GPIO2p4 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_4)
PINCONF_GPIO2p5 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_5)
PINCONF_GPIO2p6 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_6)
PINCONF_GPIO2p7 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_7)
PINCONF_GPIO2p8 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_12)
PINCONF_GPIO2p9 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_0)
PINCONF_GPIO2p10 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_1)
PINCONF_GPIO2p11 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_2)
PINCONF_GPIO2p12 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_3)
PINCONF_GPIO2p13 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_4)
PINCONF_GPIO2p14 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_5)
PINCONF_GPIO2p15 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS5|PINCONF_PIN_6)
PINCONF_GPIO3p0 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_1)
PINCONF_GPIO3p1 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_2)
PINCONF_GPIO3p2 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_3)
PINCONF_GPIO3p3 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_4)
PINCONF_GPIO3p4 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_5)
PINCONF_GPIO3p5 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_9)
PINCONF_GPIO3p6 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_10)
PINCONF_GPIO3p7 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_11)
PINCONF_GPIO3p8 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_0)
PINCONF_GPIO3p9 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_1)
PINCONF_GPIO3p10 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_2)
PINCONF_GPIO3p11 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_3)
PINCONF_GPIO3p12 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_4)
PINCONF_GPIO3p13 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_5)
PINCONF_GPIO3p14 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_6)
PINCONF_GPIO3p15 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS7|PINCONF_PIN_7)
PINCONF_GPIO4p0 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_0)
PINCONF_GPIO4p1 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_1)
PINCONF_GPIO4p2 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_2)
PINCONF_GPIO4p3 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_3)
PINCONF_GPIO4p4 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_4)
PINCONF_GPIO4p5 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_5)
PINCONF_GPIO4p6 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_6)
PINCONF_GPIO4p7 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS8|PINCONF_PIN_7)
PINCONF_GPIO4p8 =          (PINCONF_FUNC0|PINCONF_PINSA|PINCONF_PIN_1)
PINCONF_GPIO4p9 =          (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINSA|PINCONF_PIN_2)
PINCONF_GPIO4p10 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINSA|PINCONF_PIN_3)
PINCONF_GPIO4p11 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_6)
PINCONF_GPIO4p12 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_0)
PINCONF_GPIO4p13 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_1)
PINCONF_GPIO4p14 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_2)
PINCONF_GPIO4p15 =         (PINCONF_FUNC0|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_3)
PINCONF_GPIO5p0 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_0)
PINCONF_GPIO5p1 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_1)
PINCONF_GPIO5p2 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_2)
PINCONF_GPIO5p3 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_3)
PINCONF_GPIO5p4 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_4)
PINCONF_GPIO5p5 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_5)
PINCONF_GPIO5p6 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_6)
PINCONF_GPIO5p7 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS2|PINCONF_PIN_8)
PINCONF_GPIO5p8 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_1)
PINCONF_GPIO5p9 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_2)
PINCONF_GPIO5p10 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_7)
PINCONF_GPIO5p11 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS3|PINCONF_PIN_8)
PINCONF_GPIO5p12 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_8)
PINCONF_GPIO5p13 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_9)
PINCONF_GPIO5p14 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS4|PINCONF_PIN_10)
PINCONF_GPIO5p15 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_7)
PINCONF_GPIO5p16 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS6|PINCONF_PIN_8)
PINCONF_GPIO5p17 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_4)
PINCONF_GPIO5p18 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINS9|PINCONF_PIN_5)
PINCONF_GPIO5p19 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSA|PINCONF_PIN_4)
PINCONF_GPIO5p20 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_0)
PINCONF_GPIO5p21 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_1)
PINCONF_GPIO5p22 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_2)
PINCONF_GPIO5p23 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_3)
PINCONF_GPIO5p24 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_4)
PINCONF_GPIO5p25 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_5)
PINCONF_GPIO5p26 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSB|PINCONF_PIN_6)
PINCONF_GPIO6p0 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_1)
PINCONF_GPIO6p1 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_2)
PINCONF_GPIO6p2 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_3)
PINCONF_GPIO6p3 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_4)
PINCONF_GPIO6p4 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_5)
PINCONF_GPIO6p5 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_6)
PINCONF_GPIO6p6 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_7)
PINCONF_GPIO6p7 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_8)
PINCONF_GPIO6p8 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_9)
PINCONF_GPIO6p9 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_10)
PINCONF_GPIO6p10 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_11)
PINCONF_GPIO6p11 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_12)
PINCONF_GPIO6p12 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_13)
PINCONF_GPIO6p13 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSC|PINCONF_PIN_14)
PINCONF_GPIO6p14 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_0)
PINCONF_GPIO6p15 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_1)
PINCONF_GPIO6p16 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_2)
PINCONF_GPIO6p17 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_3)
PINCONF_GPIO6p18 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_4)
PINCONF_GPIO6p19 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_5)
PINCONF_GPIO6p20 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_6)
PINCONF_GPIO6p21 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_7)
PINCONF_GPIO6p22 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_8)
PINCONF_GPIO6p23 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_9)
PINCONF_GPIO6p24 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_10)
PINCONF_GPIO6p25 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_11)
PINCONF_GPIO6p26 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_12)
PINCONF_GPIO6p27 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_13)
PINCONF_GPIO6p28 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_14)
PINCONF_GPIO6p29 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_15)
PINCONF_GPIO6p30 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSD|PINCONF_PIN_16)
PINCONF_GPIO7p0 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_0)
PINCONF_GPIO7p1 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_1)
PINCONF_GPIO7p2 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_2)
PINCONF_GPIO7p3 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_3)
PINCONF_GPIO7p4 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_4)
PINCONF_GPIO7p5 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_5)
PINCONF_GPIO7p6 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_6)
PINCONF_GPIO7p7 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_7)
PINCONF_GPIO7p8 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_8)
PINCONF_GPIO7p9 =          (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_9)
PINCONF_GPIO7p10 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_10)
PINCONF_GPIO7p11 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_11)
PINCONF_GPIO7p12 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_12)
PINCONF_GPIO7p13 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_13)
PINCONF_GPIO7p14 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_14)
PINCONF_GPIO7p15 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSE|PINCONF_PIN_15)
PINCONF_GPIO7p16 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_1)
PINCONF_GPIO7p17 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_2)
PINCONF_GPIO7p18 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_3)
PINCONF_GPIO7p19 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_5)
PINCONF_GPIO7p20 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_6)
PINCONF_GPIO7p21 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_7)
PINCONF_GPIO7p22 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_8)
PINCONF_GPIO7p23 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_9)
PINCONF_GPIO7p24 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_10)
PINCONF_GPIO7p25 =         (PINCONF_FUNC4|PINCONF_INBUFFER|PINCONF_PINSF|PINCONF_PIN_11)

NUM_GPIO_PORTS =                8
NUM_GPIO_PINS =                 32
NUM_GPIO_NGROUPS =              2


$port_pin_lut = [
    [PINCONF_GPIO0p0, PINCONF_GPIO0p1, PINCONF_GPIO0p2,  PINCONF_GPIO0p3,  PINCONF_GPIO0p4,  PINCONF_GPIO0p5,  PINCONF_GPIO0p6, PINCONF_GPIO0p7,
     PINCONF_GPIO0p8, PINCONF_GPIO0p9, PINCONF_GPIO0p10, PINCONF_GPIO0p11, PINCONF_GPIO0p12, PINCONF_GPIO0p13, PINCONF_GPIO0p14, PINCONF_GPIO0p15,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], # port 0

    [PINCONF_GPIO1p0,  PINCONF_GPIO1p1,  PINCONF_GPIO1p2,  PINCONF_GPIO1p3,  PINCONF_GPIO1p4,  PINCONF_GPIO1p5,  PINCONF_GPIO1p6,  PINCONF_GPIO1p7,
     PINCONF_GPIO1p8,  PINCONF_GPIO1p9,  PINCONF_GPIO1p10, PINCONF_GPIO1p11, PINCONF_GPIO1p12, PINCONF_GPIO1p13, PINCONF_GPIO1p14, PINCONF_GPIO1p15,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], # port 1

    [PINCONF_GPIO2p0,  PINCONF_GPIO2p1,  PINCONF_GPIO2p2,  PINCONF_GPIO2p3,  PINCONF_GPIO2p4,  PINCONF_GPIO2p5,  PINCONF_GPIO2p6,  PINCONF_GPIO2p7,
     PINCONF_GPIO2p8,  PINCONF_GPIO2p9,  PINCONF_GPIO2p10, PINCONF_GPIO2p11, PINCONF_GPIO2p12, PINCONF_GPIO2p13, PINCONF_GPIO2p14, PINCONF_GPIO2p15,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], # port 2

    [PINCONF_GPIO3p0,  PINCONF_GPIO3p1,  PINCONF_GPIO3p2,  PINCONF_GPIO3p3,  PINCONF_GPIO3p4,  PINCONF_GPIO3p5,  PINCONF_GPIO3p6,  PINCONF_GPIO3p7,
     PINCONF_GPIO3p8,  PINCONF_GPIO3p9,  PINCONF_GPIO3p10, PINCONF_GPIO3p11, PINCONF_GPIO3p12, PINCONF_GPIO3p13, PINCONF_GPIO3p14, PINCONF_GPIO3p15,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], # port 3

    [PINCONF_GPIO4p0,  PINCONF_GPIO4p1,  PINCONF_GPIO4p2,  PINCONF_GPIO4p3,  PINCONF_GPIO4p4,  PINCONF_GPIO4p5,  PINCONF_GPIO4p6,  PINCONF_GPIO4p7,
     PINCONF_GPIO4p8,  PINCONF_GPIO4p9,  PINCONF_GPIO4p10, PINCONF_GPIO4p11, PINCONF_GPIO4p12, PINCONF_GPIO4p13, PINCONF_GPIO4p14, PINCONF_GPIO4p15,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], # port 4

    [PINCONF_GPIO5p0,  PINCONF_GPIO5p1,  PINCONF_GPIO5p2,  PINCONF_GPIO5p3,  PINCONF_GPIO5p4,  PINCONF_GPIO5p5,  PINCONF_GPIO5p6,  PINCONF_GPIO5p7,
     PINCONF_GPIO5p8,  PINCONF_GPIO5p9,  PINCONF_GPIO5p10, PINCONF_GPIO5p11, PINCONF_GPIO5p12, PINCONF_GPIO5p13, PINCONF_GPIO5p14, PINCONF_GPIO5p15,
     PINCONF_GPIO5p16, PINCONF_GPIO5p17, PINCONF_GPIO5p18, PINCONF_GPIO5p19, PINCONF_GPIO5p20, PINCONF_GPIO5p21, PINCONF_GPIO5p22, PINCONF_GPIO5p23,
     PINCONF_GPIO5p24, PINCONF_GPIO5p25, PINCONF_GPIO5p26,
     0,0,0,0,0], # port 5

     [PINCONF_GPIO6p0, PINCONF_GPIO6p1,  PINCONF_GPIO6p2,  PINCONF_GPIO6p3,  PINCONF_GPIO6p4,  PINCONF_GPIO6p5,  PINCONF_GPIO6p6,  PINCONF_GPIO6p7,
     PINCONF_GPIO6p8,  PINCONF_GPIO6p9,  PINCONF_GPIO6p10, PINCONF_GPIO6p11, PINCONF_GPIO6p12, PINCONF_GPIO6p13, PINCONF_GPIO6p14, PINCONF_GPIO6p15,
     PINCONF_GPIO6p16, PINCONF_GPIO6p17, PINCONF_GPIO6p18, PINCONF_GPIO6p19, PINCONF_GPIO6p20, PINCONF_GPIO6p21, PINCONF_GPIO6p22, PINCONF_GPIO6p23,
     PINCONF_GPIO6p24, PINCONF_GPIO6p25, PINCONF_GPIO6p26, PINCONF_GPIO6p27, PINCONF_GPIO6p28, PINCONF_GPIO6p29, PINCONF_GPIO6p30,
     0], # port 6

     [PINCONF_GPIO7p0, PINCONF_GPIO7p1,  PINCONF_GPIO7p2,  PINCONF_GPIO7p3,  PINCONF_GPIO7p4,  PINCONF_GPIO7p5,  PINCONF_GPIO7p6,  PINCONF_GPIO7p7,
     PINCONF_GPIO7p8,  PINCONF_GPIO7p9,  PINCONF_GPIO7p10, PINCONF_GPIO7p11, PINCONF_GPIO7p12, PINCONF_GPIO7p13, PINCONF_GPIO7p14, PINCONF_GPIO7p15,
     PINCONF_GPIO7p16, PINCONF_GPIO7p17, PINCONF_GPIO7p18, PINCONF_GPIO7p19, PINCONF_GPIO7p20, PINCONF_GPIO7p21, PINCONF_GPIO7p22, PINCONF_GPIO7p23,
     PINCONF_GPIO7p24, PINCONF_GPIO5p25,
     0,0,0,0,0,0] # port 7
]

# given the physical port and pin (P2.7) finds the GPIO port and pin (GPIO0[7])
def lookup_pin(port, pin)
    for i in 0..NUM_GPIO_PORTS-1 do
        for j in 0..NUM_GPIO_PINS-1 do
            v= $port_pin_lut[i][j]
            next if v == 0
            if (((v&PINCONF_PINS_MASK)>>PINCONF_PINS_SHIFT) == port) && (((v&PINCONF_PIN_MASK)>>PINCONF_PIN_SHIFT) == pin)
                return [i, j]
            end
        end
    end

    []
end

if ARGV.empty?
    puts "Usage: p1.6 p1_6 | gpio1[3] gpio1_3"
    exit 1
end

s= ARGV[0]

if s.start_with?("gpio")
    m = /gpio([\d+]+)[\[_](\d+)/.match(s)

    if m.nil? || m.size < 3
        puts("require gpio1[2] or gpio1_2")
        exit 1
    end
    x= m[1].to_i
    y= m[2].to_i
    if x > 7 || y > 31
        puts "pin or port out of range"
        exit 1
    end

    v= $port_pin_lut[x][y]
    if v == 0
        puts "not a valid gpio"
        exit 1
    end

    port= ((v&PINCONF_PINS_MASK)>>PINCONF_PINS_SHIFT)
    pin= ((v&PINCONF_PIN_MASK)>>PINCONF_PIN_SHIFT)


    puts "p#{port.to_s(16)}_#{pin}"

elsif s.start_with?('p')
    m = /p([0-9abcdef]+)[._](\d+)/.match(s)
    if m.nil? || m.size < 3
        puts("require p1.2 or p1_2")
        exit 1
    end

    r = lookup_pin(m[1].to_i(16), m[2].to_i)
    if r.empty?
        puts "#{s} has no GPIO"
        exit 1
    end

    puts "GPIO#{r[0]}[#{r[1]}]"

end

